<template>
  <div class="radio-group">
    <div v-for="item in $props.options" :key="item.label" class="radio">
      <Radio v-model="radioVal" v-bind="item" @change="handleChange">
        {{ item.value }}
      </Radio>
    </div>
  </div>
</template>

<script>
import { defineComponent, ref } from 'vue'
import { Radio } from 'element-ui'

export default defineComponent({
  name: 'RadioGroup',
  components: { Radio },
  props: {
    value: {
      type: String,
      default: ''
    },
    options: {
      type: Array,
      default: () => []
    }
  },
  emits: ['options-change'],
  setup(props, { emit }) {
    const radioVal = ref(props.value)

    function handleChange(e) {
      emit('options-change', e)
    }

    return {
      radioVal,
      handleChange
    }
  }
})
</script>

<style lang="scss" scoped>
.radio-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;

  .radio {
    display: flex;
    align-items: center;
    height: 36px;
  }

  & .radio:not(:last-child) {
    margin-right: 16px;
  }
}
</style>
